import 'package:flutter/material.dart';
import 'package:flutter_getx/view/home/logic.dart';
import 'package:flutter_getx/view/home/state.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:get/get.dart';

class NoticeDetail extends StatefulWidget {
  const NoticeDetail({super.key});

  @override
  State<NoticeDetail> createState() => _NoticeDetailState();
}

class _NoticeDetailState extends State<NoticeDetail> {
  final HomeLogic logic = Get.put(HomeLogic());
  final HomeState state = Get.find<HomeLogic>().state;

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    final prams = Get.arguments! as Map<String, dynamic>;
    logic.getNotifyDetail(prams['id']);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('公告详情'),
        ),
        body: ListView(children: [
          Obx(() {
            return Container(
                padding: const EdgeInsets.all(10),
                child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      // 标题
                      Text(state.notifyDetail.value.title,
                          style: const TextStyle(
                            fontSize: 18,
                            fontWeight: FontWeight.bold,
                          )),
                      const SizedBox(height: 10),
                      Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(state.notifyDetail.value.creatorName,
                                style: const TextStyle(color: Colors.grey)),
                            Text(state.notifyDetail.value.createdAt,
                                style: const TextStyle(color: Colors.grey))
                          ]),
                      const SizedBox(height: 10),
                      // 内容
                      Html(
                        data: state.notifyDetail.value.content,
                      )
                    ]));
          })
        ]));
  }
}
